package com.kyivmohyla.kma2.client.view.common;

import com.google.gwt.cell.client.TextCell;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.HasData;
import com.kyivmohyla.kma2.shared.model.UIHistory;

public class OrderHistoryWidget extends Composite {

    private final static DateTimeFormat dateFormat = DateTimeFormat.getFormat("dd.MM.yyyy HH:mm");
    private final CellTable<UIHistory> orderHistoryCellTable;

    public OrderHistoryWidget() {
        orderHistoryCellTable = new CellTable<UIHistory>();
        initWidget(orderHistoryCellTable);
        addColumns();
    }

    private void addColumns() {
        orderHistoryCellTable.addColumn(new Column<UIHistory, String>(new TextCell()) {
            @Override
            public String getValue(UIHistory object) {
                return dateFormat.format(object.getChangeDate());
            }
        }, "Change Date");
        orderHistoryCellTable.addColumn(new Column<UIHistory, String>(new TextCell()) {
            @Override
            public String getValue(UIHistory object) {
                return object.getNewStateName();
            }
        }, "New State");
        orderHistoryCellTable.addColumn(new Column<UIHistory, String>(new TextCell()) {
            @Override
            public String getValue(UIHistory object) {
                return object.getStaffName();
            }
        }, "Staff");
        orderHistoryCellTable.addColumn(new Column<UIHistory, String>(new TextCell()) {
            @Override
            public String getValue(UIHistory object) {
                return object.getCommentary();
            }
        }, "Commentary");
    }

    public HasData getOrderHistoryCellTable() {
        return orderHistoryCellTable;
    }

    public Widget asWidget() {
        return this;
    }
}
